package com.ruoyi.xuexiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.constant.KsSsjCqjlStatusEnum;
import com.ruoyi.xuexiao.domain.entity.KsSsjCqjl;
import com.ruoyi.xuexiao.service.KsSsjCqjlService;
import com.ruoyi.xuexiao.mapper.KsSsjCqjlMapper;
import lombok.AllArgsConstructor;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 矿山底数抽查-抽取记录Service实现层
 *
 * @author 齐浩宽
 * @since 2024-05-23 22:24:12
 */
@Service
@AllArgsConstructor
public class KsSsjCqjlServiceImpl extends ServiceImpl<KsSsjCqjlMapper, KsSsjCqjl> implements KsSsjCqjlService {

    KsSsjCqjlMapper ksSsjCqjlMapper;

    /**
     * 查询抽取记录
     *
     * @author 齐浩宽
     * @since 2024年5月27日17:06:54
     */
    @Override
    public List<KsSsjCqjl> queryRecords(String year) {
        LambdaQueryWrapper<KsSsjCqjl> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Strings.isNotBlank(year),KsSsjCqjl::getYear, year);
        wrapper.eq(KsSsjCqjl::getCqwc, KsSsjCqjlStatusEnum.COMPLETED.getCode());
        return ksSsjCqjlMapper.selectList(wrapper);
    }

    /**
     * 修改抽取记录状态为完成
     *
     * @author 齐浩宽
     * @since 2024年5月27日17:07:10
     */
    @Override
    public boolean updateCqwc(Integer id,String year) {
        // 筛选条件
        LambdaQueryWrapper<KsSsjCqjl> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(KsSsjCqjl::getCqwc, KsSsjCqjlStatusEnum.COMPLETED.getCode());
        wrapper.eq(KsSsjCqjl::getYear, year);
        KsSsjCqjl ksSsjCqjl = ksSsjCqjlMapper.selectById(id);
        ksSsjCqjl.setCqwc(1);
        int i = ksSsjCqjlMapper.updateById(ksSsjCqjl);
        return i == 1;
    }
}
